home *** CD-ROM | disk | FTP | other *** search
- // ListboxDlg.cpp : implementation file
- // High Tech BASIC, Copyright (C) TransEra Corp 1999, All Rights Reserved.
- //
- // Author: Sven Henze, Tech Soft GmbH (Germany)
- // Created: 22-Aug-1999
- // Last update: 28-Sep-1999
- //
-
- #include "stdafx.h"
- #include "Listbox.h"
- #include "ListboxDlg.h"
- #include "export.h"
- #include "adderdlg.h"
- #include "editdlg.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- #define LINEHEIGHT 12
- #define WIDTHADJUST 23
- #define STARTHEIGHT 370
- #define HEIGHTADJUST 30
- #define MINWIDTH 150
-
-
- char tmp[256];
-
-
- /////////////////////////////////////////////////////////////////////////////
- // ListboxDlg dialog
-
-
- ListboxDlg::ListboxDlg(CWnd* pParent /*=NULL*/)
- : CDialog(ListboxDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(ListboxDlg)
- //}}AFX_DATA_INIT
-
- m_pModeless = NULL;
- m_pModeless2 = NULL;
-
- }
-
- void ListboxDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(ListboxDlg)
- DDX_Control(pDX, IDC_LIST2, m_List2);
- DDX_Control(pDX, IDC_LIST1, m_List1);
- DDX_Control(pDX, IDC_BUTTON1, m_Butt1);
- DDX_Control(pDX, IDC_BUTTON2, m_Butt2);
- DDX_Control(pDX, IDC_BUTTON3, m_Butt3);
- DDX_Control(pDX, IDC_BUTTON14, m_Butt4);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(ListboxDlg, CDialog)
- //{{AFX_MSG_MAP(ListboxDlg)
- ON_BN_CLICKED(IDC_BUTTON13, OKPressed)
- ON_BN_CLICKED(IDC_BUTTON14, CancelPressed)
- ON_WM_CLOSE()
- ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
- ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // ListboxDlg message handlers
-
- BOOL ListboxDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- if (g_Width < MINWIDTH)
- {
- g_Width = MINWIDTH;
- }
-
- g_pWnd = this;
-
- int adjust=0;
- if (NoButtonVisible)
- {
- adjust = 28;
- }
-
-
- SetWindowText(g_Title); // set window title
-
- SetDlgItemText(IDC_STATIC0,g_Description); // set static text control text
- SetDlgItemText(IDC_LIST1,g_Lstrings); // string list text (group text)
-
- CWnd* pStaticText = GetDlgItem(IDC_STATIC0); // get pointer to static text control text
- pStaticText->SetWindowPos(NULL,0,0,g_Width+4,70+g_Height,SWP_NOZORDER | SWP_NOMOVE); // set width of static text control
-
- CWnd* pStaticL1Text = GetDlgItem(IDC_LIST1); // get pointer to multiple selection style listbox
- pStaticL1Text->SetWindowPos(NULL,0,0,g_Width-10,19+g_Height+adjust,SWP_NOZORDER | SWP_NOMOVE); // set width of static text control
-
- CWnd* pStaticL2Text = GetDlgItem(IDC_LIST2); // get pointer to single selection style listbox
- pStaticL2Text->SetWindowPos(NULL,0,0,g_Width-10,19+g_Height+adjust,SWP_NOZORDER | SWP_NOMOVE); // set width of static text control
-
- CWnd* pNewButton = GetDlgItem(IDC_BUTTON1); // get pointer to New button
- CWnd* pEditButton = GetDlgItem(IDC_BUTTON2); // get pointer to Edit button
- CWnd* pDelButton = GetDlgItem(IDC_BUTTON3); // get pointer to Delete button
- CWnd* pOKButton = GetDlgItem(IDC_BUTTON13); // get pointer to 'OK' button
- CWnd* pCancelButton = GetDlgItem(IDC_BUTTON14); // get pointer to 'Cancel' button
-
-
- // disable unused buttons
- if (NewDisabled)
- {
- m_Butt1.ModifyStyle(0, WS_DISABLED, 0);
- }
-
- if (EditDisabled)
- {
- m_Butt2.ModifyStyle(0, WS_DISABLED, 0);
- }
-
- if (DeleteDisabled)
- {
- m_Butt3.ModifyStyle(0, WS_DISABLED, 0);
- }
-
-
- if (CancelDisabled)
- {
- // center the 'OK' button
- pOKButton->SetWindowPos(NULL,(g_Width+WIDTHADJUST)/2-33,94+g_Height,60,23,SWP_NOZORDER);
- m_Butt4.DestroyWindow();
- }
- else
- {
- // center the 'OK' and 'Cancel buttons
- pOKButton->SetWindowPos(NULL,(g_Width+WIDTHADJUST)/2-72,94+g_Height,60,23,SWP_NOZORDER); // set position of OK button
- pCancelButton->SetWindowPos(NULL,(g_Width+WIDTHADJUST)/2+3,94+g_Height,60,23,SWP_NOZORDER); // set position of Cancel button
- }
-
-
- // now delete unused buttons if all buttons are disabled
- if (NoButtonVisible)
- {
- m_Butt1.DestroyWindow();
- m_Butt2.DestroyWindow();
- m_Butt3.DestroyWindow();
- }
- else
- {
- // center the 'special' buttons
- adjust = (g_Width+WIDTHADJUST)/2 - 86;
- pNewButton->SetWindowPos(NULL,12+adjust,52+g_Height,43,21,SWP_NOZORDER); // set position of 'New' button
- pEditButton->SetWindowPos(NULL,61+adjust,52+g_Height,43,21,SWP_NOZORDER); // set position of 'Edit' button
- pDelButton->SetWindowPos(NULL,109+adjust,52+g_Height,43,21,SWP_NOZORDER); // set position of 'Delete' button
- }
-
-
- // select the appropriate ListBox ressource (single/multiple style)
- if (SingleSelection)
- {
- g_pList = (CListBox*) (g_pWnd->GetDlgItem(IDC_LIST2));
- m_List1.DestroyWindow();
- }
- else
- {
- g_pList = (CListBox*) (g_pWnd->GetDlgItem(IDC_LIST1));
- m_List2.DestroyWindow();
- }
-
- // set window size
- SetWindowPos(NULL,0,0,g_Width+WIDTHADJUST,155+g_Height,SWP_NOZORDER );
-
- SetForegroundWindow();
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
-
- } // OnInitDialog
-
-
- void ListboxDlg::OnClose()
- { Closelistbox();
- CDialog::OnClose();
-
- } // OnClose
-
-
- void ListboxDlg::OKPressed()
- { Closelistbox();
- } // OKPressed
-
-
- void ListboxDlg::CancelPressed()
- { Closelistbox();
-
- } // CancelPressed
-
-
- // Delete selected item(s)
- void ListboxDlg::OnButton3()
- {
- int result, cnt, selcnt, i, j;
-
- // first check if there are any items selected
- selcnt = Getselcount(); // number of selected items
-
- if ( selcnt != 0 )
- {
- cnt = g_pList->GetCount(); // number of items in listbox
- result = MessageBox( "Are you sure to delete the selected item(s)?", g_Title, MB_ICONQUESTION | MB_YESNO | MB_APPLMODAL);
-
- if ( result == IDYES )
- {
- for ( i = cnt-1; i >=0; i-- )
- {
- j = g_pList->GetSel(i);
- if ( (j!=0) && (j!=LB_ERR) )
- {
- g_pList->DeleteString(i);
- }
-
- } // for loop
-
- } // IDYES if statement
-
- } // ( selcnt !=0 )
-
- } // OnButton3
-
-
- // Edit selected item
- void ListboxDlg::OnButton2()
- {
- int cnt, selcnt, i, j;
-
- // first check if there are any items selected
- selcnt = Getselcount(); // number of selected items
-
- if ( selcnt == 1 ) // we can only edit one item at the same time !
- {
- // now search for item
- cnt = Getcount(); // number of items in listbox
-
- i=0;
- while (Getsel(i+1)==0)
- {
- i++;
- }
-
- j=i;
-
- if ( m_pModeless2 == NULL )
- {
- m_pModeless2 = new CEditDlg(this);
- m_pModeless2->Create();
-
- CEdit* pEdit = (CEdit*) m_pModeless2->GetDlgItem(IDC_EDIT1);
-
- g_pList->GetText(j, tmp); // get listbox entry
- pEdit->SetWindowText(tmp); // transfer listbox entry into edit window
- pEdit->SetSel(0, -1, FALSE); // select the whole text
-
- (m_pModeless2->GetDlgItem(IDC_EDIT1))->SetFocus(); // give edit window focus
-
-
- }
- else
- {
- m_pModeless2->SetActiveWindow();
- }
-
- }
-
- } // OnButton2
-
-
- // reset variable
- void ListboxDlg::AdderBoxDone()
- {
- m_pModeless = NULL;
-
- } // AdderBoxDone
-
-
- // reset variable
- void ListboxDlg::EditBoxDone()
- {
- m_pModeless2 = NULL;
-
- } // EditBoxDone
-
-
- // Add a new entry
- void ListboxDlg::OnButton1()
- {
- int selcnt;
-
- // first check if there are any items selected
- selcnt = Getselcount(); // number of selected items
-
- g_bEdsort = (selcnt != 1);
-
- if ( m_pModeless == NULL ) // create window is neccessary
- {
- m_pModeless = new CAdderDlg(this);
- m_pModeless->Create();
-
- }
- else
- {
- m_pModeless->SetActiveWindow(); // windows exist, so give it the focus
- }
-
- // set focus to edit control
- (m_pModeless->GetDlgItem(IDC_EDIT1))->SetFocus();
-
- } // OnButton1
-